package com.pengtu.gsj.service.impl.jsbz;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.dao.jsbz.RoadCycleDao;
import com.pengtu.gsj.entity.app.Attachment;
import com.pengtu.gsj.entity.jsbz.RoadCycle;
import com.pengtu.gsj.service.jsbz.RoadCycleService;
import com.pengtu.gsj.service.system.SystemManageService;

@Transactional
@Service
public class RoadCycleServiceImpl implements RoadCycleService{
	@Autowired
	private RoadCycleDao roadCycleDao;
	
	@Autowired
	private SystemManageService systemManageService;
	
	
	
	@Override
	public void saveRoadCycle(RoadCycle roadCycle){
		roadCycleDao.save(roadCycle);
	}
	
	@Override
	public Page<RoadCycle> findRoadCycle(Page<RoadCycle> page, final QueryFilter queryFilter){
		return roadCycleDao.findPage(page, queryFilter);
	}
	
	@Override
	public RoadCycle getRoadCycleById(String id){
		return roadCycleDao.get(id);
	}
	
	@Override
	public void  delateRoadCycle(RoadCycle roadCycle){
		if(roadCycle.getAttachments() != null){
			for(Attachment attachment : roadCycle.getAttachments()){
				systemManageService.deleteAttachment(attachment);
			}
		}
		roadCycleDao.delete(roadCycle);
	}
	
}
